import QtQuick 2.0
import Qt3D 1.0

Ring {
    id: _root

    //position 0:Top, 1:Bottom, 2:North, 3:South, 4:West, 5:East
    property int position: 0

    property real angle: 0
    property variant axis: Qt.vector3d(0, 1, 0)
    property variant translatePos: Qt.vector3d(0, 0, 0)
    property real translateX: 0
    property real translateY: 0
    property real translateZ: 0
    property bool running: _animAngle.running | _animTranslateX.running | _animTranslateY.running | _animTranslateZ.running

    transform: [
        Rotation3D{
            angle: _root.angle
            axis: _root.axis
        },
        Translation3D{
            translate: Qt.vector3d(translateX, translateY, translateZ)
        }
    ]

    Behavior on angle{
        NumberAnimation{ id: _animAngle; duration: 100  }
    }
    Behavior on translateX{
        NumberAnimation{ id: _animTranslateX; duration: 100  }
    }
    Behavior on translateY{
        NumberAnimation{ id: _animTranslateY; duration: 100  }
    }
    Behavior on translateZ{
        NumberAnimation{ id: _animTranslateZ; duration: 100  }
    }

    function moveSelector(isPlus){
                  // 0, 1, 2, 3, 4, 5
//        var plus  = [3, 4, 5, 1, 2, 0]; //T W B N E S
//        var minus = [5, 3, 4, 0, 1, 2];
//        var plus  = [3, 4, 5, 2, 0, 1]; //T W B N E S
//        var minus = [4, 5, 3, 0, 1, 2];
        var plus  = [3, 2, 5, 4, 1, 0]; //T W B N E S
        var minus = [5, 4, 1, 0, 3, 2];

        if(_root.running){
        }else if(isPlus){
            _root.position = plus[_root.position];
        }else{
            _root.position = minus[_root.position];
        }
    }

    StateGroup{
        states: [
            State{
                //Top
                when: position == 0
                PropertyChanges {
                    target: _root
                    angle: 90
                    axis: Qt.vector3d(1, 0, 0)
                    translateY: 1
                }
            },
            State{
                //Bottom
                when: position == 1
                PropertyChanges {
                    target: _root
                    angle: 90
                    axis: Qt.vector3d(1, 0, 0)
                    translateY: -1
                }
            },
            State{
                //North
                when: position == 2
                PropertyChanges {
                    target: _root
                    translateZ: 1
                }
            },
            State{
                //South
                when: position == 3
                PropertyChanges {
                    target: _root
                    translateZ: -1
                }
            },
            State{
                //West
                when: position == 4
                PropertyChanges {
                    target: _root
                    angle: 90
                    axis: Qt.vector3d(0, 1, 0)
                    translateX: 1
                }
            },
            State{
                //East
                when: position == 5
                PropertyChanges {
                    target: _root
                    angle: 90
                    axis: Qt.vector3d(0, 1, 0)
                    translateX: -1
                }
            }
        ]
    }
}
